package com.dnzx.controller.web;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.dnzx.framework.result.ResultUtils;
import org.dnzx.framework.result.domain.Result;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.dnzx.model.ProductBO;
import com.dnzx.service.IProductService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@RestController
@RequestMapping("/web/product")
@Api(value = "/web/product",description="商品管理",produces=MediaType.APPLICATION_JSON_VALUE)
public class WebProductController {
	
	@Resource
	private IProductService productService;
	
	/**
	 * 查看
	 * @param id
	 * @return
	 */
	@GetMapping("/get/{id}")
	@ApiOperation(value = "/get/{id}",notes = "查看",httpMethod = "GET",produces=MediaType.APPLICATION_JSON_VALUE)
	public Result get(@ApiParam(value = "id") @PathVariable("id") Long id, HttpServletRequest request) {
		try {
			ProductBO productBO = this.productService.get(id);
			return ResultUtils.returnSuccess("SUCCESS", productBO);
		}catch(Exception e) {
			return ResultUtils.returnError(e.getMessage());
		}
	}
	
	/**
	 * 查询 - 不分页
	 * @param productBO
	 * @return
	 */
	@PostMapping("/queryList")
	@ApiOperation(value="/queryList",notes="查询 - 不分页：传type",httpMethod="POST",produces=MediaType.APPLICATION_JSON_VALUE)
	public Result queryList(@ApiParam(value = "实体") @RequestBody ProductBO productBO, HttpServletRequest request) {
		try {
			List<ProductBO> productBOList = this.productService.queryList(productBO);
			return ResultUtils.returnSuccess("SUCCESS", productBOList);
		}catch(Exception e) {
			e.printStackTrace();
			return ResultUtils.returnError(e.getMessage());
		}
	}

}
